num = input("Введите четырехзначное число: ")

if len(num) != 4 or not num.isdigit():
    print(0)
else:
    prime_found = False
    for length in range(4, 0, -1):
        if prime_found:
            break
        for start in range(5 - length):
            candidate = int(num[start:start+length])
            if candidate < 2:
                continue
            for i in range(2, candidate):
                if candidate % i == 0:
                    break
            else:
                print(candidate)
                prime_found = True
                break
    if not prime_found:
        print(0)
